package cn.net.chenbao.medical.mvp;

import android.view.View;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import org.xutils.http.RequestParams;
import org.xutils.x;

import java.util.List;

import cn.net.chenbao.medical.MedicalApplication;
import cn.net.chenbao.medical.R;
import cn.net.chenbao.medical.api.Api;
import cn.net.chenbao.medical.bean.Report;
import cn.net.chenbao.medical.mvp.presenter.IReportP;
import cn.net.chenbao.medical.mvp.view.IReportV;
import cn.net.chenbao.medical.util.Consts;
import cn.net.chenbao.medical.xutils.WWXCallBack;

/**
 * Created by 木头 on 2018/1/17.
 */

public class ReportP implements IReportP {
    RequestParams requestParams;
    private IReportV mReportV;

    public ReportP(IReportV reportV) {
        this.mReportV = reportV;
    }

    @Override
    public void doQuery(int mode, String startDate, String endDate, int pyFlag, long printId) {
        mReportV.loadStart(true);
        String result = null;
        switch (mode) {
            case Consts.MODE_NURSE:
                //配液报表
                result = "PyRpt";
                requestParams = new RequestParams(Api.PyRpt());
                requestParams.addBodyParameter("rptDate", startDate);
                requestParams.addBodyParameter("printId", printId + "");
                break;
            case Consts.MODE_JC:
                //进仓报表
                result = "InRpt";
                requestParams = new RequestParams(Api.InRpt());
                requestParams.addBodyParameter("rptDate", startDate);
                requestParams.addBodyParameter("printId", printId + "");
                break;
            case Consts.MODE_KBCC:
                //空包出仓报表
                result = "OutRpt";
                requestParams = new RequestParams(Api.OutRpt());
                requestParams.addBodyParameter("rptDate", startDate);
                requestParams.addBodyParameter("printId", printId + "");
                /*****************************************************************/
                //空仓报表参数
                requestParams.addBodyParameter("pyFlag", 2 + "");
                break;
            case Consts.MODE_APOTHECARY:
                //出仓报表
                result = "OutRpt";
                requestParams = new RequestParams(Api.OutRpt());
                requestParams.addBodyParameter("rptDate", startDate);
                requestParams.addBodyParameter("printId", printId + "");
                break;
            case Consts.MODE_HSJJ:
                //交接报表
                result = "JiaoRpt";
                requestParams = new RequestParams(Api.JiaoRpt());
                requestParams.addBodyParameter("rptDate", startDate);
                requestParams.addBodyParameter("pyFlag", pyFlag + "");
                break;
            case Consts.MODE_BB:
                //所有报表
                result = "QueryRpt";
                requestParams = new RequestParams(Api.QueryRpt());
                requestParams.addBodyParameter("beginDate", startDate);
                requestParams.addBodyParameter("endDate", endDate);
                requestParams.addBodyParameter("pyFlag", pyFlag + "");
                break;
        }
        requestParams.addBodyParameter("sessionId", MedicalApplication.getInstance()
                .getSessionId());
        x.http().get(requestParams, new WWXCallBack(result) {
            @Override
            public void onAfterSuccessOk(JSONObject data) {
                List<Report> reports = JSONArray.parseArray(data.getString("Data"), Report.class);
                if (reports != null) {
                    mReportV.QuerySuccess(reports);
                }
            }

            @Override
            public void onAfterFinished() {
                mReportV.loadFinish();
            }
        });

    }
}
